package com.booth.base.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;
import com.jfinal.core.Controller;
import javax.servlet.http.HttpServletRequest;

public class BaseUrlInterceptor
  implements Interceptor
{
  public void intercept(ActionInvocation arg0)
  {
    Controller controller = arg0.getController();
    HttpServletRequest request = controller.getRequest();
    StringBuilder sb = new StringBuilder().append(request.getScheme()).append("://").append(request.getServerName());
    if (request.getServerPort() != 80)
    {
      sb.append(":").append(request.getServerPort());
    }
    sb.append(request.getContextPath());

    String baseUrl = sb.toString();
    System.out.println(baseUrl);
    controller.setAttr("baseUrl", baseUrl);
  }
}